package com.ece.core.editors.config;

import java.security.Timestamp;
import java.util.Map;
import java.util.UUID;

/**
 * This bean encapsulates the properties of a review per file.
 * 
 * Little bit of background, there can be more than one comment in a single
 * file. Each comment will encapsulate comment state, path along with other
 * information specific to that comment.
 * 
 * @author Senthu Sivasambu, http://ca.linkedin.com/in/sivasambu
 * 
 */

public class Review {

    /*
     * this is not unique across multiple jvms therefore not fool proof - tr yot
     * generate this on a server
     */
    private UUID id;

    /*
     * list of comments - we do not expect this to become extremely large. We
     * need to find the individual comments sequenced according to the
     * timestamp.
     * 
     * This is unlikely to be concurrent in nature per file
     * 
     * {@link Timestamp} used here belongs to javax.security and ..it is
     * immutable.
     */
    private final Map<Timestamp, Comment> comments;

    public Review(Map<Timestamp, Comment> comments) {
	if (comments == null) {
	    throw new IllegalArgumentException("@param comment cannot be null");
	}
	this.comments = comments;
    }

    public Comment getComment(Timestamp timeStamp) {
	return comments.get(timeStamp);
    }

    public void addComment(Timestamp timeStamp, Comment comment) {
	if (timeStamp == null) {
	    throw new IllegalArgumentException(
		    "@param timeStamp cannot be null");
	}
	if (comment == null) {
	    throw new IllegalArgumentException("@param comment cannot be null");
	}
	comments.put(timeStamp, comment);
    }
}
